
import 'package:flutter/material.dart';

typedef BtnCallback = void Function();

/* 
  emptyMsg：页面为空提示内容
  imageUrl: 空图片路径
  btnMsg: 按钮内容
  onClick：点击按钮后要执行的回调
*/
class EmptyEGWidget extends StatelessWidget {
  final String emptyMsg;
  final Color? emptyMsgColor;
  final String imageUrl;
  final String btnMsg;
  final BtnCallback? onClick;
  final bool isHideButton;
  EmptyEGWidget(
      {Key? key,
      required this.emptyMsg,
      required this.imageUrl,
      this.btnMsg = '去逛逛',
      this.onClick,
      this.isHideButton = true,
      this.emptyMsgColor})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
//      constraints: BoxConstraints.expand(),
      alignment: Alignment.center,
      child: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            (imageUrl != null && imageUrl != '') ? Image.asset("$imageUrl",height: 186,width: 184,) : SizedBox(),
            SizedBox(height: 10,),
            Text(
              "$emptyMsg",
              textScaleFactor: 1.0,
              style: TextStyle(color: emptyMsgColor ?? Color(0xFF999999)),
            ),
            Offstage(
              offstage: isHideButton,
              child: Container(
                margin: EdgeInsets.only(top: 30.0),
                child: MaterialButton(
                  child: Text(
                    '$btnMsg',
                    textScaleFactor: 1.0,
                    style:
                        TextStyle(fontSize: 16.0, color:Color(0xffFAFAFA)),
                  ),
                  color: Color(0xFE4545),
                  textColor: Colors.white,
                  elevation: 0,
                  focusElevation: 0,
                  hoverElevation: 0,
                  highlightElevation: 0,
                  disabledElevation: 0,
                  onPressed: () {
                    this.onClick!();
                  },
                  minWidth: 168.0,
                  height: 40.0,
                  materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(48.0)),
                ),
              ),
            ),

          ],
        ),
      ),
    );
  }
}
